import time


import requests

headers  = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Host': 'data.10jqka.com.cn',
    'Cookie':'Hm_lvt_722143063e4892925903024537075d0d=1721390901; Hm_lvt_929f8b362150b1f77b477230541dbbc2=1721390901; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1721390901; Hm_lvt_60bad21af9c824a4a0530d5dbf4357ca=1721390904; Hm_lvt_f79b64788a4e377c608617fba4c736e2=1721390904; v=A_B2Rk8jYmiIfT5staTyqAffwbVHOdSD9h0oh-pBvMsepZ7rkkmkE0Yt-BY5'

    # 这里可以添加更多的header信息
}


headers2 = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Host': 'data.10jqka.com.cn',
    'Cookie': 'Hm_lvt_722143063e4892925903024537075d0d=1721390901; HMACCOUNT=FFE4A3ECF588E087; Hm_lvt_929f8b362150b1f77b477230541dbbc2=1721390901; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1721390901; Hm_lvt_60bad21af9c824a4a0530d5dbf4357ca=1721390904; Hm_lvt_f79b64788a4e377c608617fba4c736e2=1721390904; Hm_lpvt_722143063e4892925903024537075d0d=1721394502; log=; Hm_lpvt_929f8b362150b1f77b477230541dbbc2=1721394502; Hm_lpvt_60bad21af9c824a4a0530d5dbf4357ca=1721396929; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1721396929; Hm_lpvt_f79b64788a4e377c608617fba4c736e2=1721396929; v=A_N1z7BSkdAyuV1U-qWh0fCegvwYKIeBQbzLHqWQT5JJpB3iLfgXOlGMWyu2'
}

url_base = 'https://data.10jqka.com.cn/funds/gnzjl/#refCountId=data_55f13c2c_254'
url = 'https://data.10jqka.com.cn/funds/gnzjl/field/tradezdf/order/desc/page/1/ajax/1/free/'


# 使用session的方式。
for i in range(1, 10):
    path = 'https://data.10jqka.com.cn/funds/gnzjl/field/tradezdf/order/desc/page/'+str(i)+'/ajax/1/free'
    print(path)
    session = requests.Session()
    header = headers
    # if i > 5:
    #     header = headers2
    response = session.get(path,headers=header)
    response.raise_for_status()
    with open('2024-07-19-p'+str(i)+'.html', 'w') as file:
        file.write(response.text)
    time.sleep(61)
    print(i)






    #
# #
# # #在会话过程中，如果有接口响应头中有 set-cookie，则将自动添加到会话的Cookie中
# #
# #

# #
# # res = session.get(url=url)
# #
# # print("响应头中set-cookie：", res.headers.get("set-cookie"))
# # print("会话现有cookie：", dict(session.cookies))
#
# # r = requests.get('https://data.10jqka.com.cn/funds/ggzjl/',headers=headers)
# # r.encoding = 'gbk'
# # print(type(r))
# # print(r.status_code)
# # print(type(r.text))
# # print(r.text)
# # print(r.cookies)
#
#
#
# # 启动Chrome浏览器
# driver = webdriver.Edge()
# # 打开网页
#
# driver.get(url)
# print(driver.page_source)
# cookies = driver.get_cookies()
# str = ''
# for cookie in cookies:
#     str = str + cookie['name'] + '=' + cookie['value'] + ';'
# print(str)
# # str =  'log=; u_ukey=A10702B8689642C6BE607730E11E6E4A; u_uver=1.0.0; u_dpass=bqkFClseEeSnRKkMcwSbtq3dfetiAgAiDiu934XKOe5vmS3FP72SbsKj3Yu%2BAW5%2BHi80LrSsTFH9a%2B6rtRvqGg%3D%3D; u_did=A56AAF622DC943098695F93CC0D14D99; u_ttype=WEB;'
# # str = str + 'log=; u_ukey=A10702B8689642C6BE60o730E11E6E4A; u_uver=1.0.0; u_dpass=bqkFClseEeSnRKkMcwSbtq3dfetiAgAiDiu934XKOe5vmS3FP72SbsKj3Yu%2BAW5%2BHi80LrSsTFH9a%2B6rtRvqGg%3D%3D; u_did=A56AAF622DC943098695Fo3CC0D14D99; u_ttype=WEB;'
# headers.setdefault('Cookie', str)
# print(headers)
#
# time.sleep(10)
# # response = requests.get(url,headers=headers)
# # response = requests.head(url)
# # response.encoding = 'gbk'
# #
# # print(response.text)
# # # 确保请求成功,如果不成功会抛出异常
# # response.raise_for_status()
# # print(response.text)


# print()
print('1')


